﻿using Aquarinum.WebSocekt.ClientSdk.NET35.Interfaces;

namespace Aquarinum.WebSocekt.ClientSdk.NET35
{
    public class WebsocketClientFactory
    {
        #region 单例封装

        private static DefaultWebsocketClient _instance;
        private static readonly object Instancelocker = new object();


        /// <summary>
        ///     获取默认client
        /// </summary>
        /// <returns></returns>
        public static IWebsocketClient GetDefaultClient()
        {
            //没有第一重 instance == null 的话，每一次有线程进入 GetInstance()时，均会执行锁定操作来实现线程同步，
            //非常耗费性能 增加第一重instance ==null 成立时的情况下执行一次锁定以实现线程同步
            if (_instance == null)
                lock (Instancelocker)
                {
                    //Double-Check Locking 双重检查锁定
                    if (_instance == null) _instance = new DefaultWebsocketClient();
                }

            return _instance;
        }

        /// <summary>
        ///     todo 获取自定义client
        /// </summary>
        /// <returns></returns>
        public static IWebsocketClient GetClient<T>() where T : IWebsocketClient
        {
            return null;
        }

        #endregion
    }
}